|
1
|
|
|
import { |
|
2
|
|
|
Entity, |
|
3
|
|
|
Column, |
|
4
|
|
|
PrimaryGeneratedColumn, |
|
5
|
|
|
ManyToOne, |
|
6
|
|
|
OneToMany |
|
7
|
|
|
} from 'typeorm'; |
|
8
|
|
|
import { Customer } from '../Customer/Customer.entity'; |
|
9
|
|
|
import { User } from '../HumanResource/User/User.entity'; |
|
10
|
|
|
import { BillingItem } from './BillingItem.entity'; |
|
11
|
|
|
import { Quote } from './Quote.entity'; |
|
12
|
|
|
|
|
13
|
|
|
export enum BillingStatus { |
|
14
|
|
|
DRAFT = 'draft', |
|
15
|
|
|
SENT = 'sent', |
|
16
|
|
|
PAYED = 'payed', |
|
17
|
|
|
CANCELED = 'canceled' |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
@Entity() |
|
21
|
|
|
export class Billing { |
|
22
|
|
|
@PrimaryGeneratedColumn('uuid') |
|
23
|
|
|
private id: string; |
|
24
|
|
|
|
|
25
|
|
|
@Column('enum', {enum: BillingStatus, nullable: false}) |
|
26
|
|
|
private status: BillingStatus; |
|
27
|
|
|
|
|
28
|
|
|
@Column({type: 'varchar', nullable: false, unique: true}) |
|
29
|
|
|
private billingId: string; |
|
30
|
|
|
|
|
31
|
|
|
@Column({type: 'timestamp', default: () => 'CURRENT_TIMESTAMP'}) |
|
32
|
|
|
private createdAt: Date; |
|
33
|
|
|
|
|
34
|
|
|
@Column({type: 'timestamp'}) |
|
35
|
|
|
private expiryDate: string; |
|
36
|
|
|
|
|
37
|
|
|
@ManyToOne(type => User, {nullable: false}) |
|
38
|
|
|
private owner: User; |
|
39
|
|
|
|
|
40
|
|
|
@ManyToOne(type => Quote, {nullable: true}) |
|
41
|
|
|
private quote: Quote; |
|
42
|
|
|
|
|
43
|
|
|
@ManyToOne(type => Customer, {nullable: false}) |
|
44
|
|
|
private customer: Customer; |
|
45
|
|
|
|
|
46
|
|
|
@OneToMany( |
|
47
|
|
|
type => BillingItem, |
|
48
|
|
|
billingItem => billingItem.billing |
|
49
|
|
|
) |
|
50
|
|
|
items: BillingItem[]; |
|
51
|
|
|
|
|
52
|
|
|
constructor( |
|
53
|
|
|
billingId: string, |
|
54
|
|
|
status: BillingStatus, |
|
55
|
|
|
expiryDate: string, |
|
56
|
|
|
owner: User, |
|
57
|
|
|
customer: Customer, |
|
58
|
|
|
quote?: Quote |
|
59
|
|
|
) { |
|
60
|
|
|
this.billingId = billingId; |
|
61
|
|
|
this.status = status; |
|
62
|
|
|
this.expiryDate = expiryDate; |
|
63
|
|
|
this.owner = owner; |
|
64
|
|
|
this.customer = customer; |
|
65
|
|
|
this.quote = quote; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public getId(): string { |
|
69
|
|
|
return this.id; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public getBillingId(): string { |
|
73
|
|
|
return this.billingId; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public getExpiryDate(): string { |
|
77
|
|
|
return this.expiryDate; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public getStatus(): BillingStatus { |
|
81
|
|
|
return this.status; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public getCreatedAt(): Date { |
|
85
|
|
|
return this.createdAt; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public getCustomer(): Customer { |
|
89
|
|
|
return this.customer; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public getOwner(): User { |
|
93
|
|
|
return this.owner; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public getQuote(): Quote { |
|
97
|
|
|
return this.quote; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|